//写一些app的状态操作
import { setCookie, getCookie, removeCookie } from '@/utils/cookie.js';
import store from '../../store'
const app = {
	state: {//状态初始值
		sidebar: {
			userId: getCookie('userId'),
			apiKey: getCookie('apiKey'),
			appId: "1",
			Url: "",
			dirPart: "/",
			//详细域名
			otherJsp: 'webAPI.jsp?',
			mallJsp: 'mall.jsp?',
		},
	},
	mutations: {//修改状态值
		TOOGGLE_USER(state, value) {
			state.sidebar.userId = value;
		},
		TOOGGLE_APIURL(state, value) {
			if (value == "production") {
				var apiUrl = "https://bjy.51yunkeyi.com/";
				var KEY = 'Tts#5322chqwaR$34'
				state.sidebar.Url = apiUrl;
				state.sidebar.apiKey = KEY;
				state.sidebar.dirPart = "spell_a/";
			} else if (value == "development") {
				var apiUrl = "https://e.amjhome.com/";
				var KEY = 'amj_b5e9sdfd6ws325'
				state.sidebar.Url = apiUrl;
				state.sidebar.apiKey = KEY;
				state.sidebar.dirPart = "baojiayou_a/";
			} else {
				state.sidebar.Url = '';
				state.sidebar.apiKey = '';
				state.sidebar.dirPart = '';
			}
		},
	},
	actions: {//动作，可以调用 mutation
		//登入
		toggleUSER: ({ commit }, value) => {
			console.log(value);
			setCookie('userId', value, 15);
			commit('TOOGGLE_USER', value);
		},
		//正式/测试接口
		toggleAPIURL: ({ commit }, apiUrl) => {
			//console.log(apiUrl);
			commit('TOOGGLE_APIURL', apiUrl);
		},
		//登出
		Logout({ commit }) {
			return new Promise(resolve => {
				//清除cookie
				removeCookie('userId');
				removeCookie('accountPwd');
				removeCookie('accountName');
				resolve();
			})
		}
	}
}
export default app;
